/*
 *  POJ1836: Alignment
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int   N;
float h[1000];

int dpl[1000];
int dpr[1000];

float stk[1001];
int   top;

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    // get input
    cin >> N;

    for (int i = 0; i < N; i++) cin >> h[i];

    // initialize
    top    = 1;
    stk[1] = h[0];

    dpl[0] = 1;

    // dp of LIS from left to right
    for (int i = 1; i < N; i++) {
        if (h[i] > stk[top]) {
            stk[++top] = h[i];
        } else {
            // binary search(lower_bound)
            // *lower_bound(stk + 1, stk + top, h[i]) = h[i];
            int lo = 1, hi = top;
            while (hi > lo) {
                int mid = (lo + hi) / 2;

                if (h[i] > stk[mid]) lo = mid + 1;
                else                 hi = mid;
            }

            stk[lo] = h[i];
        }

        dpl[i] = top;
    }

    // initialize
    top    = 1;
    stk[1] = h[N - 1];

    dpr[N - 1] = 1;

    // dp of LIS from rigth to left
    for (int i = N - 2; i >= 0; i--) {
        if (h[i] > stk[top]) {
            stk[++top] = h[i];
        } else {
            // binary search(lower_bound)
            // *lower_bound(stk + 1, stk + top, h[i]) = h[i];
            int lo = 1, hi = top;
            while (hi > lo) {
                int mid = (lo + hi) / 2;

                if (h[i] > stk[mid]) lo = mid + 1;
                else                 hi = mid;
            }

            stk[lo] = h[i];
        }

        dpr[i] = top;
    }

    // for (int i = 0; i < N; i++) cout << dpl[i] << '\t';
    // cout << endl;
    // for (int i = 0; i < N; i++) cout << dpr[i] << '\t';
    // cout << endl;

    int maxi = 0;
    for (int i = 0; i < N - 1; i++)
        maxi = max(maxi, dpl[i] + dpr[i + 1]);

    cout << N - maxi << endl;

    return 0;
}

/*-------- Functions --------*/

